package controller;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * A threaded work description that waits for input from the GCom
 * model/subsystem and sends these messages to the GUI via the
 * {@link controller.Controller}. Giving this responsibility to a separate
 * thread increases the responsiveness of the application.
 * 
 */
public class OutputQueueHandler implements Runnable {

    private final LinkedBlockingQueue<String> outputQueue;
    private final Controller control;

    public OutputQueueHandler(final LinkedBlockingQueue<String> workqueue,
            final Controller control) {
        outputQueue = workqueue;
        this.control = control;
    }

    @Override
    public void run() {
        while (true) {
            try {
                control.submitOutput(outputQueue.take());
            } catch (final InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
}
